package com.app.datasource;

import com.alibaba.druid.pool.DruidDataSource;

import javax.sql.DataSource;

/**
 * @author ch
 * @date 2022/12/14 11:46
 */
public class DruidDatasourceFactory extends AbstractDatabaseFactory {
    @Override
    public DataSource init(DatasourceInfo info) {
        try {
            DruidDataSource druidDataSource = new DruidDataSource();
            druidDataSource.setUrl(info.getUrl());
            druidDataSource.setDriverClassName(info.getDriverClassName());
            druidDataSource.setUsername(info.getUsername());
            druidDataSource.setPassword(info.getPassword());
            druidDataSource.init();
            return druidDataSource;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
